package spider.zookeeper.util;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * StringUtils
 *
 * @author Archx[archx@foxmail.com]
 * @date 2017/4/7
 */
public abstract class StringUtils {

    public static final String EMPTY = "";

    /**
     * 打印堆栈信息
     *
     * @param e 异常
     * @return
     */
    public static String printStackTrace(Throwable e) {
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        printer.flush();
        return writer.getBuffer().toString();
    }

    /**
     * 判断对象是否为空
     *
     * @param object
     * @return
     */
    public static boolean isEmpty(Object object) {

        if (object instanceof String) {
            String string = (String) object;
            return EMPTY.equals(string) || EMPTY.equals(string.trim()) || "null".equals(string);
        }
        return object == null;
    }
}
